﻿@using DNA.Mvc;
@using DNA.Mvc.Publishing;
@using System;
@using System.Web.Mvc;
@using System.Web.Mvc.Ajax;
@using DNA.Mvc.jQuery;
@using DNA.Mvc.Text;
@helper PostStateImage(Article article, UrlHelper Url)
    {
        if (article.IsPublished)
        {
            if (article.Posted > DateTime.Now.AddDays(-3))
            { 
    <img style="margin-left: 5px;" src="@Url.Content("~/Content/Images/new.gif")" alt="new_post" title="New post"/>
            }
        }
        else
        {
    <img style="margin-left: 5px;" src="@Url.Content("~/Content/Images/draft.gif")" alt="draft" "Draft"/>
        }

        if (!string.IsNullOrEmpty(article.Password))
        {
    <img style="margin-left: 5px;" src="@Url.Content("~/Content/Images/icon_key_16.gif")" alt="password" "Password protect"/>
        }

        if (article.IsPrivate)
        {
    <img style="margin-left: 5px;" src="@Url.Content("~/Content/Images/icon_lock.gif")" alt="private_post" "Private post"/>
        }
}
@helper ShareTo(ArticleWrapper article)
    {
    <table style="width: 100%;">
        <tr>
            <td>
                <g:plusone size="small"></g:plusone>
            </td>
            <td>
                <script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>
                <script type="IN/Share" data-url="@article.PermaLink" data-counter="right"></script>
            </td>
            <td style="width: 100px;">@Twitter.TweetButton("Horizontal")
            </td>
            <td>@Facebook.LikeButton(href: article.PermaLink, action: "recommend", buttonLayout: "button_count", width: 150, height: 20)
            </td>
            <td style="text-align: right;">
                <span>@DNA.Mvc.UI.GE.Global("publishing", "ShareTo"):</span>@LinkShare.GetHtml(article.Title, pageLinkBack: article.PermaLink)
            </td>
        </tr>
    </table>
}
@helper PostLink(Article article, int maxLength = -1, string cssClass = "d-post-title", string target = "_self")
    {
        var _article = new ArticleWrapper(article);
        var content = _article.GetGlobalizationContent();
        var _title = content.Title;
        var _class = !string.IsNullOrEmpty(cssClass) ? "class=" + cssClass : "";
        if (maxLength > 0)
        {
            if (!string.IsNullOrEmpty(_title) && _title.Length > maxLength)
            {
                _title = _title.Substring(0, maxLength) + "...";
            }
        }
    <a href="@_article.PermaLink" @_class title="@content.Title" target="@target">@_title</a>
}
@helper PostSummary(Article article, int maxLength = 255)
    {
        var _article = new ArticleWrapper(article);
        var content = _article.GetGlobalizationContent();
        var _summary = content.Summary;

        if (string.IsNullOrEmpty(_summary))
        {
            if (_article.ContentFormat == 2)
            {
                _summary = TextEngine.Text(TextEngine.Wiki(content.Body.Replace("{toc}", "")).ToString());
            }
            else
            {
                _summary = TextEngine.Text(content.Body);
            }
        }

        if (maxLength > 0)
        {
            if (!string.IsNullOrEmpty(_summary) && _summary.Length > maxLength)
            {
                _summary = _summary.Substring(0, maxLength) + "...";
            }
        }
    <p class="d-post-summary" title="@content.Summary" style="margin:0px;">
        @_summary
    </p>
}
@helper TagLink(string tagName)
    {
    <a href="@(UrlResolver.ApplicationPath + "/publishing/" + WebSiteContext.Current.Web.Name + "/tags/" + tagName)" title="@tagName">
        @tagName
    </a>
}